package com.jsz.peini.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class MyInterceptor implements HandlerInterceptor{
	  
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object obj) throws Exception {
    	if(request.getSession().getAttribute("sellerId")==null && obj.toString().indexOf("SellerOrderController.login") == -1){
    		response.sendRedirect(request.getContextPath()+"/seller/login");
    		//response.getWriter().write("<script language=javascript>location.href="+request.getContextPath()+"'/seller/login';</script>");
			return false;
		}
	  return true;
    }  
    
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object obj, ModelAndView mav) throws Exception { }
    
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object obj, Exception e) throws Exception { } 
	
}
